package org.example.salesystem.controller;

import org.example.salesystem.entity.Report;
import org.example.salesystem.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/report")
@CrossOrigin(origins="*")
public class ReportController {
    @Autowired
    private ReportService reportService;

    @PostMapping("/submitReport")
    public ResponseEntity<Map<String, Object>> submitReport(@RequestBody Report report) {
        Map<String, Object> response = new HashMap<>();
        
        try {
            boolean success = reportService.submitReport(report);
            if (success) {
                response.put("status", 200);
                response.put("message", "举报提交成功");
            } else {
                response.put("status", 500);
                response.put("message", "举报提交失败");
            }
        } catch (Exception e) {
            response.put("status", 500);
            response.put("message", "系统错误，请稍后重试");
        }
        
        return ResponseEntity.ok(response);
    }
} 